from openpyxl import Workbook
from openpyxl.styles import *

wb = Workbook()
ws = wb.active

''' 
ws['A1'] = "姓名"
cell = ws['B1']
cell.value = "语文"
ws.cell(row=1, column=3, value="数学")
ws.cell(row=1, column=4, value="英语") 
'''

allData = {
  "1": ["0","姓名","语文","数学","英语","总分"],
  "2": ["0","莉莉","90","95","90","0"],
  "3": ["0","蜜蜜","85","100","88","0"],
}


for row in allData.keys():
  length = len(allData[row])

  for column in range(1, length):
    """ 
    '<' not supported between instances of 'str' and 'int'    需要强转
    Row or column values must be at least 1                   行数和列数也需要从1开始计数
    """
    new_row = int(row)
    value = allData[row][column]
    cell_value = "%s" % value

    ws.cell(row=new_row, column=column, value=cell_value)

  # 计算成绩  
  # 从第二行  第二列开始
  if(int(row) > 1):
    sum = 0
    for column in range(2, length):
      if column == length-1:
        value = int(sum)
        ws.cell(row=int(row), column=int(column), value=value)
      else:
        sum += int(allData[row][column])
        

wb.save("./helpTeacher.xlsx")